﻿package scrn;


import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;


public class Test04 {


public static void createGUI() {

	JFrame frame = new JFrame("Test frame");
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	String[] columnNames = { "Name", "Last modified", "Type" };

	String[][] data = { { "addins", "02.11.2006 19:15", "Folder" },
			{ "AppPatch", "03.10.2006 14:10", "Folder" },
			{ "assembly", "02.11.2006 14:20", "Folder" },
			{ "Boot", "13.10.2007 10:46", "Folder" },
			{ "Branding", "13.10.2007 12:10", "Folder" },
			{ "Cursors", "23.09.2006 16:34", "Folder" },
			{ "Debug", "07.12.2006 17:45", "Folder" },
			{ "Fonts", "03.10.2006 14:08", "Folder" },
			{ "help.exe", "08.11.2006 18:23", "File" } };

	JPanel mainPanel = new JPanel();
	mainPanel.setLayout(new BorderLayout());

	final JTable table = new JTable(data, columnNames);
	JScrollPane scrollPane = new JScrollPane(table);
	mainPanel.add(scrollPane, BorderLayout.CENTER);

	table.addMouseListener(new MouseListener() {

		public void mouseClicked(MouseEvent event) {

		}


		public void mouseEntered(MouseEvent event) {

		}


		public void mouseExited(MouseEvent event) {

		}


		public void mousePressed(MouseEvent event) {

			if (event.getButton() == MouseEvent.BUTTON3) {
				Point point = event.getPoint();
				int column = table.columnAtPoint(point);
				int row = table.rowAtPoint(point);
				table.setColumnSelectionInterval(column, column);
				table.setRowSelectionInterval(row, row);
			}
		}


		public void mouseReleased(MouseEvent event) {

		}

	});

	frame.getContentPane().add(mainPanel);

	frame.setPreferredSize(new Dimension(450, 180));
	frame.pack();
	frame.setLocationRelativeTo(null);
	frame.setVisible(true);
}


public static void main(String[] args) {

	javax.swing.SwingUtilities.invokeLater(new Runnable() {

		public void run() {

			JFrame.setDefaultLookAndFeelDecorated(true);
			createGUI();
		}
	});
}

}
